{% extends base %}

{% block body_top %}

    {% init default_content = "" %}
    {% init show_tab = True %}

    <link rel="stylesheet" type="text/css" href="{{_server_home}}/_static/lib/webuploader/webuploader.css">
    <script type="text/javascript" src="{{_server_home}}/_static/lib/webuploader/webuploader.nolog.min.js"></script>
    <script type="text/javascript" src="{{_server_home}}/_static/js/message/message.js?ts={{_ts}}"></script>

    <input class="msg-search-key" type="hidden" value="{{key}}"/>
    <input class="default-content-input" type="hidden" value="{{default_content}}"/>
{% end %}

{% block body_left %}
    <!-- 编辑 -->
    {% include message/component/message_edit.html %}

    {% init message_tag = "" %}
    {% init p = "" %}
    <!-- Tab页 -->
    {% init message_tab = "log" %}
    {% init default_content = "" %}
    {% init date = "" %}
    {% init is_task_tag = False %}
    
    <div class="card">    
        <div class="card-title btn-line-height">
            {% if is_task_tag %}
                <span>搜索待办</span>
            {% else %}
                <span>搜索随手记</span>
            {% end %}

            <div class="float-right">
                {% if is_task_tag %}
                    <a class="btn btn-default" href="{{_server_home}}/message?tag=task">待办</a>
                {% else %}
                    <a class="btn btn-default" href="{{_server_home}}/message?tag=log">随手记</a>
                {% end %}
                {% include common/button/back_button.html %}
            </div>
        </div>
    </div>

    {% if is_task_tag %}
    <div class="card x-tab-box" data-tab-key="tag" data-tab-default="all">
        <a class="x-tab" href="{{_server_home}}/message?tag=task.search&key={{quote(key)}}" data-tab-value="task.search">
            待办
        </a>
        <a class="x-tab" href="{{_server_home}}/message?tag=done.search&key={{quote(key)}}" data-tab-value="done.search">
            已完成
        </a>
    </div>
    {% end %}

    <!-- 事件转换 -->
    {% include message/component/message_event.html %}

    {% include message/component/message_keyword_info.html %}

    {% if date != "" %}
    <div class="card btn-line-height">
        <span class="tag info">日期</span>
        <span>{{date}}</span>
    </div>
    {% end %}

    <!-- 内容区域 -->
    {% include message/component/message_list.html %}

    <script type="text/javascript">

        xnote.state.message.messageTag = "{{message_tag}}";
        xnote.state.message.tag = "{{tag}}";

        $(function (e) {
            function getParamTag() {
                return xnote.getUrlParam("tag", "search");
            }

            function getParamPage() {
                var page = getUrlParam("page");
                if (page == undefined) {
                    return 1;
                } else {
                    return page;
                }
            }

            function getParamKey() {
                // getUrlParam 获取参数空格会被处理成`+`
                return $(".msg-search-key").val();
            }

            function onMessageRefresh() {
                var params = getUrlParams();

                params.tag  = getParamTag();
                params.page = getParamPage();
                params.key = getParamKey();

                window.doRefreshMessageList(params);
            }

            function onMessageCreated() {
                onMessageRefresh();
            }

            xnote.on("message.updated", onMessageRefresh);
            xnote.on("message.created", onMessageCreated);

            // 触发更新事件
            xnote.fire("message.updated");
        });
    </script>

{% end %}


{% block body_right %}
    <div class="desktop-only">
        {% include note/component/group_special_folder.html %}
        {% include message/component/right/tags.html %}
    </div>
{% end %}
